#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 1001
#define inf 0x3fffffff
int n, x;
int lose[maxn], win[maxn], use[maxn];
long dp[maxn];
int main()
{
    cin >> n >> x;
    for (int i = 1; i <= n; ++i)
    {
        cin >> lose[i] >> win[i] >> use[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = x; j >= 0; --j)
        {
            if (j >= use[i])
                dp[j] = max(dp[j - use[i]] + win[i], dp[j] + lose[i]);
            else
                dp[j] = dp[j] + lose[i];
        }
    }
    cout << 5 * dp[x] << endl;
    return 0;
}